home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
Delphi Magazine Collection 2001
/
Delphi Magazine Collection 20001 (2001).iso
/
DISKS
/
Issue38
/
Clinic
/
StpKey3U.pas
< prev
next >
Wrap
Pascal/Delphi Source File
|
1998-07-07
|
3KB
|
103 lines
unit StpKey3U;
interface
uses
WinProcs, WinTypes, Messages, SysUtils, Classes, Graphics, Controls, Forms,
Dialogs, StdCtrls, Menus;
type
TForm1 = class(TForm)
Label1: TLabel;
Label2: TLabel;
Label3: TLabel;
Edit1: TEdit;
Edit2: TEdit;
Edit3: TEdit;
Edit4: TEdit;
Edit5: TEdit;
Edit6: TEdit;
Edit7: TEdit;
Edit8: TEdit;
Label4: TLabel;
procedure FormKeyDown(Sender: TObject; var Key: Word;
Shift: TShiftState);
procedure FormKeyPress(Sender: TObject; var Key: Char);
private
{ Private declarations }
public
procedure WMMenuChar(var Msg: TWMMenuChar); message wm_MenuChar;
end;
var
Form1: TForm1;
implementation
{$R *.DFM}
function GetShiftState: TShiftState;
var
KeyState: TKeyboardState;
begin
Result := [];
GetKeyboardState(KeyState);
if KeyState[vk_Shift] and $80 <> 0 then Include(Result, ssShift);
if KeyState[vk_Control] and $80 <> 0 then Include(Result, ssCtrl);
if KeyState[vk_Menu] and $80 <> 0 then Include(Result, ssAlt);
if KeyState[vk_LButton] and $80 <> 0 then Include(Result, ssLeft);
if KeyState[vk_RButton] and $80 <> 0 then Include(Result, ssRight);
if KeyState[vk_MButton] and $80 <> 0 then Include(Result, ssMiddle);
end;
function GetCtrlLetter(Ch: Char): Char;
begin
{ Take away one less than the letter A }
Result := Chr(Ord(Ch) - Ord(Pred('A')))
end;
procedure TForm1.FormKeyDown(Sender: TObject; var Key: Word;
Shift: TShiftState);
begin
if (Key = vk_F2) and (Shift = []) then
begin
Caption := 'F2 was pressed at ' + TimeToStr(Time);
Key := 0
end;
end;
procedure TForm1.FormKeyPress(Sender: TObject; var Key: Char);
var
Shift: TShiftState;
begin
Shift := GetShiftState;
{ Check Escape }
if (Key = Chr(vk_Escape)) and (Shift = []) then
begin
Color := RGB(Random(256), Random(256), Random(256));
Key := #0
end;
{ When Ctrl+letter is pressed, the character code is the }
{ position in the alphabet held by the uppercase letter }
if (Key = GetCtrlLetter('S')) and (Shift = [ssCtrl]) then
begin
Application.Minimize;
Key := #0
end;
end;
procedure TForm1.WMMenuChar(var Msg: TWMMenuChar);
begin
if UpCase(Msg.User) = 'S' then
begin
Caption := 'Alt+S was pressed at ' + TimeToStr(Time);
LongRec(Msg.Result).Hi := 1 { I've handled this }
end
else
inherited { I haven't handled this }
end;
initialization
Randomize
end.